$(function(){
    $("#regist_button").click(function(){
        //console.log('111111111')
        //清除提示信息
        $("#warning_1").hide()
        $("#warning_2").hide()
        $("#warning_3").hide()
        $("#warning_4").hide()

        //1.获取请求参数
        var name = $("#regist_username").val().trim();
        var nick = $("#nickname").val().trim();
        var password = $("#regist_password").val().trim();
        var final_password = $("#final_password").val().trim();
        //console.log(name,nickname,password,final_password)
        //2.检查格式
        //两次密码一致 所有属性非空
        var ok = true
        if(name == ""){
            ok = false
            //console.log("111111111111")
            $("#warning_1 span").html("用户名为空");
            $("#warning_1").show()
        }
        if(nick == ""){
            ok = false
            $("#warning_4 span").html("昵称为空");
            $("#warning_4").show()
        }
        if(password == ""){
            ok = false
            $("#warning_2 span").html("密码为空");
            $("#warning_2").show()
        }else{
            if(password.length<6){
                ok = false
                $("#warning_2 span").html("密码需要六位以上");
                $("#warning_2").show()
            }
        }
        if(final_password != password){
            ok = false
            $("#warning_3 span").html("与密码不一致");
            $("#warning_3").show()
        }
        //3.发送请求
        if(ok){
            $.ajax({
                url: "http://localhost/user/regist.do",
                type: "post",
                data: {"name":name,"nick":nick,"password":password},
                dataType: "json",
                success: function(result){
                    console.log(result)
                    if(result.status == 0){//注册成功
                        alert(result.msg) //提示
                        $("#back").click() //切换到登录页
                    }else if(result.status == 1){ //用户名已被占用
                        $("#warning_1 span").html(result.msg);
                        $("#warning_1").show()
                    }
                },
                error: function(){
                    alert("注册失败，请联系管理员:136xxxxxxxx")
                }

            })
        }


    })
})